<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:cgf="http://www.centralgold.com.br/facelets"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="manutencaoForm">

        <rich:panel>
            <f:facet name="header">Cadastrar Manutenções da Frota</f:facet>
			
			<h:panelGrid columns="2">
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Veículo:</ui:define>
					<h:inputText value="#{cadastrarManutencao.automovelSelecionado.marca}/#{cadastrarManutencao.automovelSelecionado.modelo}" 
						readonly="true"/>
				</s:decorate>
				
				<a:commandButton value="Selecionar" onclick="#{rich:component('modalPesqAutomovel')}.show()"
					reRender="pesqFrotaForm"/>
			</h:panelGrid>
			
			<rich:dataTable id="tabelaManutencoes" 
				value="#{cadastrarManutencao.listaManutencoes}"
				rows="10"
				onRowMouseOver="this.style.backgroundColor='#6495ED'"
       			onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
				var="_man">
				
				<a:queue ignoreDupResponses="true"/>	
				
				<rich:column>
					<f:facet name="header">
						<h:selectBooleanCheckbox value="#{cadastrarManutencao.selecionadoTodos}" >
							<a:support event="onchange" 
								action="#{cadastrarManutencao.selecionaTodos()}"
								reRender="tabelaManutencoes"/>
						</h:selectBooleanCheckbox>
					</f:facet>
					<h:selectBooleanCheckbox value="#{_man.selecionado}" />				
				</rich:column>
				
				<rich:column filterBy="#{_aut.marca}" filterEvent="onkeyup">
					<f:facet name="header">Tipo de Manutenção</f:facet>
					<h:outputText value="#{_man.tipoManutencao.nome}" />	
					<a:queue ignoreDupResponses="true"/>			
				</rich:column>
				
				<rich:column filterBy="#{_aut.marca}" filterEvent="onkeyup">
					<f:facet name="header">Data</f:facet>
					<h:outputText value="#{_man.data}">
						<s:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>				
				</rich:column>
				
				<rich:column rendered="#{identity.hasRole('CADASTRAR_MANUTENCOES_GRAVAR')}">
					<f:facet name="header"></f:facet>
					<h:commandButton value="EDITAR"
						image="/img/btn_editar.png"
						alt="EDITAR"
						title="EDITAR" 
						action="#{cadastrarManutencao.editar(_man)}" />				
				</rich:column>
			</rich:dataTable>
			<rich:datascroller for="tabelaManutencoes" renderIfSinglePage="false"/>
        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="novo" value="Novo" action="#{cadastrarManutencao.novo()}"
            	rendered="#{identity.hasRole('CADASTRAR_MANUTENCOES_GRAVAR') and cadastrarManutencao.exibeBotaoNovo()}"/>
            <h:commandButton id="excluir" value="Excluir" action="#{cadastrarManutencao.excluir()}"
            	rendered="#{identity.hasRole('CADASTRAR_MANUTENCOES_EXCLUIR')}"
            	onclick="javascript:if(!confirm('Tem certeza que deseja excluir?'))return false;"/>
        </div>

    </h:form>
    
    <rich:modalPanel id="modalPesqAutomovel" height="450" width="800">
           	<f:facet name="header">
	            <h:panelGroup>
	                <h:outputText value="Pesquisar Frota"></h:outputText>
	            </h:panelGroup>
	        </f:facet>
	        <f:facet name="controls">
	            <h:panelGroup>
	                <h:graphicImage value="/img/close.png" styleClass="hidelink" id="hidelink"/>
	                <rich:componentControl for="modalPesqAutomovel" attachTo="hidelink" operation="hide" event="onclick"/>
	            </h:panelGroup>
	        </f:facet>

			<h:form id="pesqFrotaForm">
				<a:region>
					<h:panelGrid columns="2">
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Marca:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.marca}"
								maxlength="50"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Modelo:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.modelo}"
								maxlength="50"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Cor:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.cor}"
								maxlength="20"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Placa:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.placa}"
								maxlength="7"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Chassi:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.chassi}"
								maxlength="50"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Ano Fabricação:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.anoFabricacao}"
								maxlength="4"
								onkeydown="Mascara(this,Integer)"
								onkeyup="Mascara(this,Integer)"/>
						</s:decorate>
						
						<s:decorate template="/layout/edit.xhtml">
							<ui:define name="label">Ano Modelo:</ui:define>
							<h:inputText value="#{cadastrarManutencao.automovelPesquisa.anoModelo}"
								maxlength="4"
								onkeydown="Mascara(this,Integer)"
								onkeyup="Mascara(this,Integer)"/>
						</s:decorate>
					</h:panelGrid>
					<br/>
					<center>
						<a:commandButton value="PESQUISAR" action="#{cadastrarManutencao.pesquisaAutomoveis()}"
							reRender="pesqFrotaForm"/>
					</center>
					<br/><br/>
				</a:region>
				<rich:dataTable value="#{cadastrarManutencao.listaAutomoveis}"
					var="_aut"
					rows="5"
					onRowMouseOver="this.style.backgroundColor='#6495ED'"
       				onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
					id="tabelaAutomoveis">
					<rich:column>
						<f:facet name="header">Marca</f:facet>
						<h:outputText value="#{_aut.marca}"/>
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Modelo</f:facet>
						<h:outputText value="#{_aut.modelo}"/>
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Cor</f:facet>
						<h:outputText value="#{_aut.cor}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Placa</f:facet>
						<h:outputText value="#{_aut.placaFormatada}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Chassi</f:facet>
						<h:outputText value="#{_aut.chassi}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Ano Fabricação</f:facet>
						<h:outputText value="#{_aut.anoFabricacao}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Ano Modelo</f:facet>
						<h:outputText value="#{_aut.anoModelo}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header"></f:facet>
						<a:commandLink value="SELECIONAR"
							action="#{cadastrarManutencao.selecionarAutomovel(_aut)}"
							onclick="#{rich:component('modalPesqAutomovel')}.hide()"
							reRender="manutencaoForm"/>
					</rich:column>
				</rich:dataTable>
				<rich:datascroller for="tabelaAutomoveis" />
			</h:form>             
        </rich:modalPanel>

 </ui:define>
</ui:composition>
